package com.itboye.ihomebank.util;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.adapter.ListDialogAdapter;
import com.itboye.ihomebank.util.dialog.RxDialog;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/3/5 0005.
 */

public class ListDialog extends RxDialog {
    ImageView dialog_cancelImg;
    TextView dialog_title;
    RecyclerView dialog_rv;
    ListDialogAdapter mListDialogAdapter;

    public ImageView getDialog_cancelImg() {
        return dialog_cancelImg;
    }

    public void setDialog_cancelImg(ImageView dialog_cancelImg) {
        this.dialog_cancelImg = dialog_cancelImg;
    }

    public ListDialog(Context context, int themeResId) {
        super(context, themeResId);
        initView();
    }

    public ListDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initView();
    }

    public ListDialog(Context context) {
        super(context);
        initView();
    }

    public ListDialog(Context context, float alpha, int gravity) {
        super(context, alpha, gravity);
        initView();
    }
    public ListDialog(Context context, String title, List<String> list, int type){
        super(context);
        initView();
        dialog_title.setText(title);
        mListDialogAdapter=new ListDialogAdapter(context,list,type);
        LinearLayoutManager manager=new LinearLayoutManager(context);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        dialog_rv.setLayoutManager(manager);
        dialog_rv.setAdapter(mListDialogAdapter);
    }
    public ListDialog(Context context, String title, List<String> list, int type,List<String> contract_no){
        super(context);
        initView();
        dialog_title.setText(title);
        mListDialogAdapter=new ListDialogAdapter(context,list,type,contract_no);
        LinearLayoutManager manager=new LinearLayoutManager(context);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        dialog_rv.setLayoutManager(manager);
        dialog_rv.setAdapter(mListDialogAdapter);
    }

    public  void setListDialogHeigh(){
        WindowManager m = getWindow().getWindowManager();
        Display d = m.getDefaultDisplay();  //为获取屏幕宽、高
        android.view.WindowManager.LayoutParams p = getWindow().getAttributes();  //获取对话框当前的参数值
        p.height = (int) (d.getHeight() * 0.6);   //高度设置为屏幕的0.3
        p.width = (int) (d.getWidth() * 0.9);    //宽度设置为屏幕的0.5
        getWindow().setAttributes(p);     //设置生效
    }
    private void initView() {
        View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_list, null);
        dialog_title= (TextView) dialogView.findViewById(R.id.dialog_title);
        dialog_cancelImg= (ImageView) dialogView.findViewById(R.id.dialog_cancelImg);
        dialog_rv= (RecyclerView) dialogView.findViewById(R.id.dialog_rv);
        this.setCanceledOnTouchOutside(false);
        this.setCancelable(false);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);

        setContentView(dialogView);
    }

}
